<?PHP
session_start();
include_once "ini.php";
$id_cam = $_GET['id_cam'];
$json = array();
$json[0]=$id_cam;
$json[1]=array();
dbconnect();
$correspondants = ($id_cam < $_SESSION['id_user'])?$id_cam.":".$_SESSION['id_user']:$_SESSION['id_user'].":".$id_cam;

$query = "SELECT * FROM chat WHERE correspondants = '".$correspondants."' ORDER BY id_chat DESC LIMIT 5;";
$result = mysql_query($query);
if (!$result)
{
    echo "SQL error : ", $query;
    exit ;
}
else
{
$i=0;
    $html = "";
    while ($tab = mysql_fetch_assoc($result)) //row:tableau basique, via bum�rique ;; assoc ou array:tableau associatif
    {
        $array[$i]= stripslashes($tab['message'])."<br />";
		$i++;
    }
	$j=0;
	for($i=count($array);$i>=0;$i--){
	$json[1][$j] .= $array[$i];
	$j++;
	}
   echo json_encode($json);
}

dbclose();
?>
